*Mader, Matthias/Scotto, Thomas J./Reifler, Jason/Gries, Peter H./Isernia, Pierangelo/Schoen, Harald. 2018. 
*How political are national identities? A comparison of the United States, the United Kingdom, and Germany in the 2010s. In: Research & Politics.

*Stata 14.2 reproduction code
*Reproduces the results reported in the Appendix, section A6.

*** Data Set: Smith, Tom W., Marsden, Peter V., and Hout, Michael, General Social Surveys, 1972-2016 [machine-readable data file] /Principal
*	Investigator, Smith, Tom W.; Co-Principal Investigators, Peter V. Marsden and Michael Hout; Sponsored by National Science
*	Foundation. --NORC ed.-- Chicago: NORC, 2017.
*** Download data from http://gss.norc.org/Documents/stata/gss_stata_with_codebook.zip (accessed 5/4/17)

	use "GSS7216_R1a.dta", clear

********************************************************************************************************************* 	
*** Recoding ***
********************************************************************************************************************* 	

*** National ID
	* How important is being an American to you, where 0 is not at all important and 10 is the most important thing in your life?
	fre amimp
	
	gen id1 = amimp / 10
	
	*To begin, we have some questions about where you live: your neighborhood or village, your town or city, your county, and so on. How close do you feel to America?
	fre clseusa
	
	gen id2 = (4 - clseusa) * 1/3
	fre id2
	
	*Some people say the following things are important for being truly American. Other say they are not important. How important do you think each of the following is: —to feel American?
	fre amfeel
	
	gen id3 = (4 - amfeel) * 1/3
	fre id3
	
	pwcorr id1 id2 id3
	
	egen id_ind_r1 = rowmean(id1 id2 id3)

	gen id_ind_r2 = (id1 + id2 + id3) / 3
	

*** Party ID
	*United States: Generally speaking, do you usually think of yourself as a Republican, Democrat, Independent or what?
	*(If Republican order Democrat) Would you call yourself a strong or not a very strong Republican or Democrat?
	*(If Independent) Do you think of yourself as closer to the Republican or Democratiic party?
	fre partyid

	recode partyid (3 4 5 6 = 0 "No Rep. ID") (2 = 1) (1 = 2) (0 = 3 "Strong Democrat") (7 = .), gen(us_dem)
	label variable us_dem "Party ID Democrat"
	gen us_dem_r = us_dem / 3
	tab partyid us_dem_r, mis

	recode partyid (0 1 2 3 = 0 "No Rep. ID") (4 = 1) (5 = 2) (6 = 3 "Strong Republican") (7 = .), gen(us_rep)
	label variable us_rep "Party ID Democrat"
	gen us_rep_r = us_rep / 3

	tab us_dem_r us_rep_r, mis

	recode partyid (4 5 6 = 1 "Republican") (0 1 2 = 2 "Democrat")  (3 = 3 "Independent") (7 = .), gen(us_pi1)
	tab partyid  us_pi1

	recode partyid (0 = 7 "Strong Democrat") (1 = 6 "Not very strong Democrat") (2 = 5 "Independent, close Democrat") (3 = 4 "Independent") ///
				   (4 = 3 "Independent, close Republican") (5= 2 "Not every strong Republican") (6 = 1 "Strong Republican") (7 = .), gen(us_pi2)
	tab us_pi2 partyid, mis

	mvdecode partyid, mv(7 = .)
	gen us_pi3 = partyid / 6
	
	recode partyid (0 1 2 3 4 5 = 0 "else") (6 = 1 "Strong Republican") (7 = .), gen(us_srep)
	
*** Ideology --- liberal/conservative
	*We hear a lot of talk these days about liberals and conservatives. I'm going to show you a seven-point scale on which the political views that people might
	*hold are arranged from extremely liberal--point 1--to extremely conservative--point 7. Where would you place yourself on this scale?
	fre polviews

	gen us_ideo = (polviews - 1) / 6
	tab polviews us_ideo
		
	recode polviews (4 5 6 7 = 0 "Moderate/right wing") (3 = 1) (2 = 2) (1 = 3 "Extremely liberal"), gen(us_lib)
	gen us_lib_r = us_lib / 3

	recode polviews (1 2 3 4 = 0 "Moderate/left wing") (5 = 1) (6 = 2) (7 = 3 "Extemely conservative"), gen(us_cons)
	gen us_cons_r = us_cons / 3
		
	recode polviews (1 2 3 4 5 6 = 0 "else") (7 = 1 "Strong Conservative"), gen(us_scons)
	
*** Ideology --- Left/right
	tab year, sum(leftrght)
	*only available for 2014


*** Authoritarianism
	tab year, sum(obey)
	tab year, sum(spanking)
	
	*Do you strongly agree, agree, disagree, or strongly disagree that it is sometimes necessary to discipline a child with a good, hard spanking?
	fre spanking
	gen auth1 = (4 - spanking) *1/3
	tab spanking auth1, mis

	*Which three qualities listed on this card would you say are the most desirable for a child to have? Which one of these three is the most desirable of all?
	* - That he obeys his parents well
	fre obey
	gen auth2= .
	replace auth2 = 0 if obey == 2 | obey == 3 | obey == 4 | obey == 5 
	replace auth2 = 1 if obey == 1
	tab obey auth2, mis

	egen auth_ind1 = rowmean(auth1 auth2)
	gen auth_ind2 = (auth1 + auth2) / 2

*** First Generation
	fre born
	recode born (2 = 1) (1 = 0), gen(firstgen)
	tab born firstgen, mis
	
*** Second Generation
	*Were both your parents born in this country?
	fre parborn
	
	gen secondgen = .
	replace secondgen = 0 if parborn !=.i & parborn !=.n & parborn != 8
	replace secondgen = 1 if parborn == 8
	tab parborn secondgen, mis
	
*** Age
	fre age
	gen age_dec = age / 10
	
*** Education
	gen educ_yrs = educ

*** Race
	gen white = .
	replace white = 0 if race == 2 | race == 3 
	replace white = 1 if race == 1
	
	gen black = .
	replace black = 0 if race == 1 | race == 3 
	replace black = 1 if race == 2
	
*** Gender
	fre sex
	recode sex (1 = 0) ( 2 = 1), gen(female)
	
	
********************************************************************************************************************* 	
*** Analysis ***
********************************************************************************************************************* 	

* Model 1 --- Huddy & Khatib
reg id_ind_r1 us_pi3 us_ideo auth_ind1 firstgen secondgen age_dec white black educ_yrs female if year == 1996 [pweight = wtssall]
estimates store m1

// How large is the reference category (Independents)? total: N = 457; effective: N = 97
fre us_pi3 if year == 1996
fre us_pi3 if id_ind_r1 != . & us_ideo != . & auth_ind1 != . & firstgen != . & secondgen != . & age_dec != . & white != . & black != . & educ_yrs != . & female & year == 1996

*Model 2 --- party ID as separate categories
reg id_ind_r1 ib4.us_pi2 us_ideo auth_ind1 firstgen secondgen age_dec white black educ_yrs female if year == 1996 [pweight = wtssall]
estimates store m2

*Model 3 --- party ID as separate categories and ideology split at the middle
reg id_ind_r1 ib4.us_pi2 us_cons_r us_lib_r auth_ind1 firstgen secondgen age_dec white black educ_yrs female if year == 1996 [pweight = wtssall]
estimates store m3

*Model 4 --- dummies for Strong Republican and Strong Conservative
reg id_ind_r1 1.us_pi2 7.polviews auth_ind1 firstgen secondgen age_dec white black educ_yrs female if year == 1996 [pweight = wtssall]
estimates store m4


*Table 
esttab m1 m2 m3 m4 using table_gss.rtf, replace ///
stats(r2 N , fmt(%9.2g) labels("R2" "N")) ///
cells(b(star fmt(2)) se(par fmt(2) )) ///
drop(4.us_pi2) ///
varlabels( ///
us_pi3 "PI (strong Democrat to strong Republican)" ///
us_ideo "Ideology (extremely liberal to extremely conservative)" ///
1.us_pi2 "PI Republican (strong)" ///
2.us_pi2 "PI Republican (not very strong)" ///
3.us_pi2 "PI Independent (close Republican)" ///
5.us_pi2 "PI Independent (close Democrat)" ///
6.us_pi2 "PI Democrat (not very strong)" ///
7.us_pi2 "PI Democrat (strong)" ///
us_cons_r "Ideology (conservative)" ///
us_lib_r "Ideology (liberal)" ///
7.polviews "Ideology dummy (strong conservative)" ///
auth_ind1 "Authoritarianism" ///
firstgen "First generation" ///
secondgen "Second generation" ///
age_dec "Age (in decades)" ///
white "White" ///
black "Black" ///
educ_yrs "Years of education" ///
female "Female" ///
_cons "Constant") ///
order(us_pi3 1.us_pi2 2.us_pi2 3.us_pi2 5.us_pi2 6.us_pi2 7.us_pi2 us_ideo us_cons_r us_lib_r 7.polviews) ///
title("Table 1: Determinants of American National Attachment: GSS 1996") ///
addnotes("Notes: Reported are unstandardized linear regression coefficients with standard errors in parentheses; all variables vary from 0 to 1 except age and education, which are measured in years; reference category of the party ID dummies in model 3 are Independents;* p<.05, ** p<.01, *** p<.001.") /// 
varwidth(40) modelwidth(15)	
